from socket import *
from threading import Thread


def recvData(udpSocket):
    while True:
        data = udpSocket.recvfrom(1024)
        print(">>{}:{}".format(data[1],data[0]),end="\n")

def sendData(udpSocket):
    while True:
        sendInfo = input("<<")
        udpSocket.sendto(sendInfo.encode("gb2312"),(destIp,destProt))

destIp = ""
destProt = 0

def main():
    global destIp
    global destProt

    udpSocket = socket(AF_INET,SOCK_DGRAM)
    udpSocket.bind(("",7799))
    
    destIp = input("请输入对方的IP：")
    destProt = int(input("请输入对方端口"))

    tr = Thread(target=recvData,args=(udpSocket,))
    ts = Thread(target=sendData,args=(udpSocket,))
    tr.start()
    ts.start()

    tr.join()
    ts.join()

if __name__ == "__main__":
    main()
